/*
 * 静默时间设置模块
 */
define("func/aisSetting",[
	"leaflet",
    "func/base",
    "control/panel",
    "plugins/ajaxpoll",
    
],function(L){
	L.ICT.Func.add("AisSetting",{
		Class: L.Class.extend({
			initialize:function(){
				this.ictmap = L.ict.app.ictmap;
                this.dateUtil = L.ict.app.util.dateTime;
                this.dialog = L.ict.app.util.dialog;
                this.menu = L.ict.app.menu;
                this.menuid = "ict_menu_main_ais";
                this.config = Project_ParamConfig.AreaSettingCongig;
                this.ajax = new L.ICT.Ajax();
                this._container = null;
                this._popPanel = null;
                this._drawPopPanel = null;
                this._resultPopPanel = null;
                this._layer = null;
                this._layerType = null;
			},
			 start: function () {
                if(this._container || this._popPanel) {
                    return;
                }
                this.ictmap.OperateState.jktj = true;
                this._initUi();
                this._initEvts();
                this._container.find("input[type=radio]").eq(0).click();
                this._container.find("input[type=checkbox]").eq(0).click();
                this.menu.mainmenu.deactiveMenuExceptOne(this.menuid);
                this.menu.mainmenu.disableMenuExceptOne(this.menuid);
                this.menu.mainmenu.deactivePortInfo(); //退出港口菜单
            },
			 stop: function () {
                if(this._popPanel) { this._popPanel.remove(); }
                if(this.ictmap.map.hasLayer(this._layer)) {
                    this.ictmap.map.removeLayer(this._layer);
                }
                if(this.ictmap.map.hasLayer(this._locatelayer)){
                  this.ictmap.map.removeLayer(this._locatelayer);
                }
                if(this._drawPopPanel) {
                    this._drawPopPanel.remove();
                }
                if(this._resultPopPanel) {
                    this._resultPopPanel.close();
                }
                if(this._timer) {
                    clearInterval(this._timer);
                    this._timer = null;
                }
                this.ictmap.OperateState.jktj = false;
                this.ictmap.deactivate();
                this.menu.mainmenu.deactiveMenu(this.menuid);
                this.menu.mainmenu.enableMenu();
                this._container = null;
                this._popPanel = null;
                this._drawPopPanel = null;
                this._resultPopPanel = null;
                this._layer = null;
            },
             _initUi: function () {
                var options = {
                    title: '静默时间设置',
                    width: 300,
                    height: 200,
                    right: 200,
                    top: 200
                };
                var content = this._container = $(this.getContentHTML());
                options.contentHTML = content;
                var pop = this._popPanel = new L.ICT.PopPanel(options);
                pop.show();
                pop.on("popPanelRemove", function () {
                    this._popPanel = null;
                    this._container = null;
                    this.stop();
                }, this);
            },
              getContentHTML: function () {
                var html = [];
                html.push('<div class="aisSettingContainer">');
                html.push('<div class="form-group">');
                html.push('<label>静默时间(分钟)：<input type="text" class="aisValue"  value="5"></label>');
                html.push('</div>');
                html.push('<p class="msg"></p>');
                html.push('<div class="btnDiv">');
                html.push('<button type="button" class="okAisBtn">保存</button>');
                // html.push('<button type="button" class="cancelBtn">取消</button>');
                html.push('</div>');
                html.push('</div>');
                return html.join("");
            },
            _initEvts: function () {
                var self = this;
                var $msg =  self._container.find(".msg");
                var aisValue=self._container.find(".aisValue");
                
                //保存
                self._container.find(".okAisBtn").on("click", function () {
                    // var startTime = self._container.find(".startTime").val();
                    // var endTime = self._container.find(".endTime").val();
                    $msg.html("");
                    // console.log(aisValue);
                    var url=self.config.aisSettingUrl;
                    var date={};
                    date.closetime=aisValue.val()*60===''?300:aisValue.val()*60;
                    // console.log(date);
                    //检查
                    if(aisValue.val()=='') {
                        $msg.html("请输入时间");
                        return;
                    }
                    self.ajax.post(url,date,true,this,function(res){
               
                        if(res){
                            if(res.state !== 1){
                                this.dialog.alert("提示",res.msg.error);
                            }else{
                                // console.log(res.msg);
                                self.stop();
                            }
                        }
                  })
                    
                 
                });

                
            }

		})
	})
})